package com.hhsjtest.testjenkins;


import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import java.util.ArrayList;
import java.util.List;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_splash);
        String type = "drawable";
        String pkgeName = getPackageName();

        int resId1 = getResources().getIdentifier("img_guidepage01", type, pkgeName);
        int resId2 = getResources().getIdentifier("img_guidepage02", type, pkgeName);
        int resId3 = getResources().getIdentifier("img_guidepage03", type, pkgeName);
        int resId4 = getResources().getIdentifier("img_guidepage04", type, pkgeName);
        int resId5 = getResources().getIdentifier("img_guidepage05", type, pkgeName);

        List<View> views = new ArrayList<>();

        if (resId1 != 0) {
            views.add(getPageView(R.layout.layout_splash_normal, resId1));
        }

        if (resId2 != 0) {
            views.add(getPageView(R.layout.layout_splash_normal, resId2));
        }

        if (resId3 != 0) {
            views.add(getPageView(R.layout.layout_splash_normal, resId3));
        }

        if (resId4 != 0) {
            views.add(getPageView(R.layout.layout_splash_normal, resId4));
        }

        if (resId5 != 0) {
            views.add(getPageView(R.layout.layout_splash_last, resId5));
        }

        ViewPager pager = findViewById(R.id.viewpager);

        pager.setAdapter(new GuidePageAdapter(views));
    }

    private View getPageView(int layoutId, int imgResId) {
        LayoutInflater inflater = LayoutInflater.from(this);
        View pageView = inflater.inflate(layoutId, null);
        ImageView imgPage = (ImageView) pageView.findViewById(R.id.image);
        imgPage.setBackgroundResource(imgResId);
        return pageView;
    }

    public void jump_main(View view) {
        startActivity(new Intent(this, MainActivity.class));
    }
}
